package com.tvunetworks.center.user.controller;

import com.github.pagehelper.PageInfo;
import com.tvunetworks.center.common.model.LoginUser;
import com.tvunetworks.center.common.model.param.PeerIdParam;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.user.annotation.Logined;
import com.tvunetworks.center.user.model.param.PageCustomizedChannelParam;
import com.tvunetworks.center.user.model.vo.CustomizedChannelVo;
import com.tvunetworks.center.user.model.vo.customized.TCanLiveRVo;
import com.tvunetworks.center.user.service.CustomizedChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: tvucc-aggregator
 * @description: CustomizedChannelController 定制化 CC，查询 R 列表
 * @author lebronchen
 * @create: 2020-03-17 08:58
 **/
@RestController
@RequestMapping("/channel")
public class CustomizedChannelController {

    @Autowired
    private CustomizedChannelService customizedChannelService;

    /**
     *
     * @param loginUser loginUser
     * @param param param
     * @return Result
     */
    @PostMapping("/page")
    public Result pageChannel(@Logined LoginUser loginUser, @RequestBody PageCustomizedChannelParam param){
        param.format();
        param.setUserId(loginUser.getId());
        PageInfo<CustomizedChannelVo> pageInfo = customizedChannelService.pageChannel(param);
        return ResultUtil.success(pageInfo);
    }

    /**
     *
     * @param loginUser loginUser
     * @param param param
     * @return Result
     */
    @PostMapping("/listR")
    public Result listR(@Logined LoginUser loginUser, @RequestBody PeerIdParam param) {
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        TCanLiveRVo vo = customizedChannelService.listR(loginUser.getId(), param);
        return ResultUtil.success(vo);
    }

}
